Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for offlineGoogleAnalytics config in workbox-build config #1610

Merged
merged 3 commits into from
Aug 22, 2018

Conversation

jeffposnick
Copy link
Contributor

R: @philipwalton
CC: @hoten

Fixes #1568

The name of the new boolean config property (defaulting to false) is offlineGoogleAnalytics, and it's being added to generateSW and generateSWString modes of workbox-build. It could also be used in the wrappers around workbox-build, like workbox-cli and workbox-webpack-plugin.

A custom config would still require either using importScripts to pull in a separate file while in generateSW mode, or switching to injectManifest mode. But for the basic functionality, where all you want is

workbox.googleAnalytics.initialize();

this should be sufficient.

Assuming this PR looks good, we'll need to get https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config updated once we release this, as part of what will presumably be Workbox v3.5.0.

@philipwalton
Copy link
Member

How about you can pass true to include it, or (optionally) you can pass an object or a function, which gets used as the argument to workbox.googleAnalytics.initialize()?

@jeffposnick
Copy link
Contributor Author

It's historically been messy when converting from an workbox-build option that might have non-primitive values (like options set to a function) into the equivalent string representation.

#1598 just took care of that for one case, when folks might end up setting runtimeCaching.options.plugins to a function value. I guess we could follow that model and support usage like:

offlineGoogleAnalytics: {
  hitFilter: (params) => {
    const queueTimeInSeconds = Math.round(params.get('qt') / 1000);
    params.set('cm1', queueTimeInSeconds);
  },
},

Do you feel like enough folks end up needing custom configs that the (slight) extra complexity is worthwhile? Might as well?

@philipwalton
Copy link
Member

I think it's worth it, if it's possible.

When not using any customization options, users have no way of knowing if their offline analytics are working, so I'd like to encourage more usage of the customization options wherever possible.

@jeffposnick
Copy link
Contributor Author

Okay, I've used the technique from #1598 and passing in a full range of config options, including functions, seems to work.

@workbox-pr-bot
Copy link
Collaborator

PR-Bot Size Plugin

Changed File Sizes

No file sizes have changed.

New Files

No new files have been added.

All File Sizes

View Table
File Before After Change GZipped
packages/workbox-background-sync/build/workbox-background-sync.prod.js 3.51 KB 3.51 KB 0% 1.45 KB
packages/workbox-broadcast-cache-update/build/workbox-broadcast-cache-update.prod.js 1.12 KB 1.12 KB 0% 584 B
packages/workbox-build/build/_types.js 41 B 41 B 0% 61 B
packages/workbox-build/build/index.js 4.02 KB 4.02 KB 0% 1.57 KB
packages/workbox-cache-expiration/build/workbox-cache-expiration.prod.js 3.89 KB 3.89 KB 0% 1.37 KB
packages/workbox-cacheable-response/build/workbox-cacheable-response.prod.js 587 B 587 B 0% 345 B
packages/workbox-cli/build/app.js 6.76 KB 6.76 KB 0% 2.27 KB
packages/workbox-cli/build/bin.js 2.32 KB 2.32 KB 0% 1.03 KB
packages/workbox-core/build/workbox-core.prod.js 7.18 KB 7.18 KB 0% 2.84 KB
packages/workbox-google-analytics/build/workbox-google-analytics.prod.js 2.12 KB 2.12 KB 0% 1.03 KB
packages/workbox-navigation-preload/build/workbox-navigation-preload.prod.js 522 B 522 B 0% 298 B
packages/workbox-precaching/build/workbox-precaching.prod.js 5.57 KB 5.57 KB 0% 2.15 KB
packages/workbox-range-requests/build/workbox-range-requests.prod.js 1.63 KB 1.63 KB 0% 797 B
packages/workbox-routing/build/workbox-routing.prod.js 2.87 KB 2.87 KB 0% 1.31 KB
packages/workbox-strategies/build/workbox-strategies.prod.js 4.52 KB 4.52 KB 0% 1.17 KB
packages/workbox-streams/build/workbox-streams.prod.js 1.66 KB 1.66 KB 0% 765 B
packages/workbox-sw/build/workbox-sw.js 1.50 KB 1.50 KB 0% 810 B
packages/workbox-webpack-plugin/build/generate-sw.js 8.04 KB 8.04 KB 0% 2.57 KB
packages/workbox-webpack-plugin/build/index.js 742 B 742 B 0% 470 B
packages/workbox-webpack-plugin/build/inject-manifest.js 10.30 KB 10.30 KB 0% 3.23 KB

Workbox Aggregate Size Plugin

9.76KB gzip'ed (65% of limit)
25.5KB uncompressed

@jeffposnick jeffposnick changed the title Support for offlineGoogleAnalytics: true in workbox-build config Support for offlineGoogleAnalytics config in workbox-build config Aug 22, 2018
Copy link
Member

@philipwalton philipwalton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jeffposnick jeffposnick merged commit f2e3165 into master Aug 22, 2018
@jeffposnick jeffposnick deleted the offline-ga-config-option branch August 22, 2018 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants